package cz.cuni.amis.episodic.bayes.utils;

import cz.cuni.amis.episodic.dybanem.DBN;
import cz.cuni.amis.episodic.dybanem.Evidence;
import cz.cuni.amis.episodic.dybanem.ProbabilityUtils;

import java.io.PrintStream;
import java.util.Collection;

import smile.Network;

public class JSmileUtil {

    
    public static void printNetworkEvidence(Network net, PrintStream out) {
        for (String n : net.getAllNodeIds()) {
            if (net.isEvidence(n)) {
                String e = net.getEvidenceId(n);
                System.out.println(n + " = " + e);
            }
        }
    }

    public static String dbnNodeId(String nodeName, int t) {
        if (t > 0) {
            return nodeName + "_" + t;
        } else {
            return nodeName;
        }
    }

    /**
     * Computes Kullback-Liebrer divergence of P and Q.
     *
     * @param network
     * @param nodeP
     * @param nodeQ
     * @return
     */
    public static double kullbackLiebrerDivergence(Network network, String nodeP, String nodeQ) {
        double[] probP = network.getNodeValue(nodeP);
        double[] probQ = network.getNodeValue(nodeQ);
        return ProbabilityUtils.kullbackLiebrerDivergence(probP, probQ);
    }
}
